#define   LED   13
#define   SPLIT   58 // ASCII of ":" is 58
#define   STD_LOOP_TIME  10

int lastLoopTime = STD_LOOP_TIME;
int lastLoopUsefulTime = STD_LOOP_TIME;
unsigned long loopStartTime = 0;

float value1 = 10; 
float value2 = 10.1;
float value3 = -20.5;

void Send() {  
  Serial.print(value1,DEC);    Serial.print(",");
  Serial.print(value2,DEC);    Serial.print(",");
  Serial.print(value3,DEC);    Serial.println(); // send  a "\n"
}

union u_tag {
  byte b[4];
  float fval;
} u;

void serialEvent(){
  if(Serial.available() > 0){               
    char ParamName = Serial.read(); 
    delay(5);
    if(Serial.read() == SPLIT){
      if(Serial.available() >= 4){
        u.b[3] = Serial.read(); 
        u.b[2] = Serial.read(); 
        u.b[1] = Serial.read(); 
        u.b[0] = Serial.read(); 
        Serial.flush();
        
        switch (ParamName){
          case 'a': if(u.fval == 52.5)
                    {digitalWrite(LED,1);}
                    break;
          case 'b': if(u.fval == -20.6)
                    {digitalWrite(LED,0);}
                    break;
          default: return;
        }
      }
    }
  }
}
void setup() {
    Serial.begin(115200);
    Serial.flush();
    pinMode(LED, OUTPUT);
}
void loop()
{
  Send();
  LoopTiming();
}
void LoopTiming()
{
  // loop timing control
  lastLoopUsefulTime = millis() - loopStartTime;
  if(lastLoopUsefulTime < STD_LOOP_TIME)
    delay(STD_LOOP_TIME - lastLoopUsefulTime);
  lastLoopTime = millis() - loopStartTime;
  loopStartTime = millis();
}
